package fitnesshub.mapper;

import com.github.pagehelper.Page;
import fitnesshub.pojo.dto.CoursePageQueryDTO;
import fitnesshub.pojo.entity.Course;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface CourseMapper {
    /**
     * 根据教练id查询课程是否存在
     * @param coachId
     * @return
     */
    @Select("select count(*) from course where coach_id = #{coachId}")
    Integer existsByCoachId(Integer coachId);

    /**
     * 课程分页
     * @param coursePageQueryDTO
     * @return
     */
    Page<Course> pageQuery(CoursePageQueryDTO coursePageQueryDTO);

    /**
     * 根据id查询课程
     * @param courseId
     * @return
     */
    @Select("select * from course where course_id = #{courseId}")
    Course getById(Integer courseId);

    /**
     * 插入一条记录
     * @param course
     * @return
     */
    @Insert("insert into course (course_name, coach_id, course_duration, course_description, course_price, create_time, update_time, image) " +
            "VALUES " +
            "(#{courseName},#{coachId},#{courseDuration},#{courseDescription},#{coursePrice},#{createTime},#{updateTime},#{image})")
    void insert(Course course);

    /**
     * 编辑课程
     * @param course
     */
    void update(Course course);

    /**
     * 根据id删除课程
     * @param courseId
     * @return
     */
    @Delete("delete from course where course_id = #{courseId}")
    void deleteById(Integer courseId);
}
